﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace rambla.raws.rats
{
    public class inputProfiles
    {
        private ratsConnection conn;

        internal inputProfiles(ratsConnection conn)
        {
            this.conn = conn;
        }

        public Input[] items
        {
            get
            {
                return conn.getObjects<Input>("/input/");
            }
        }

        public void deleteItem(Input item){
            conn.deleteObject("/input/" + item.id + "/");
        }

        public void createItem(Input item)
        {
            conn.postObject<Input>("/input", item);
        }

        public void updateItem(Input item)
        {
            conn.postObject<Input>("/input/" + item.id + "/", item);
        }

        public Input getItem(string id)
        {
            return conn.getObject<Input>("/input/" + id + "/");
        }

        public Input getItemByName(string name)
        {
            Input ret = null;
            foreach (Input item in this.items)
            {
                if (item.name == name)
                {
                    ret = item;
                }
            }
            return ret;
        }
    }

    [XmlRoot(Namespace = "http://rambla.be/raws/ns-metadata/1.0", ElementName = "params")]
    public class Input
    {
        ///<summary>
        /// unique (numerical) identifier for the input profile, given by the RATS server when creating it
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string id;

        ///<summary>
        /// a unique name for the input profile, given by the client in the request
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string name;

        ///<summary>
        ///a description of the input profile
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string description;

        ///<summary>
        /// identifies the kind of import operation (current choices are 'download', 'ftp' and 'rass')
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string method;

        ///<summary>
        /// base URI (starting with http:// or ftp://) to which the job's 'src_location' value must be added for determining the import location (if applicable)
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string base_uri;

        ///<summary>
        /// the name of the Rambla CDN to import from (if applicable)
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string cdn;

        ///<summary>
        /// maximum size allowed for source files (in Mb)
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string max_size;
    }
}
